//
//  OptionalTableViewCell.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/3.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "OptionalTableViewCell.h"

@implementation OptionalTableViewCell


//  增长颜色
//#define RED_COLOR   ColorWithRGB(0xd23d38)
//#define GREEN_COLOR  ColorWithRGB(0x3dba8a)



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showOrHiddenLabel) name:@"showOrHiddenLabel" object:nil];
    
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
//    self.editingStyle = UITableViewCellEditingStyleDelete;
//    [self setValue:@"UITableViewCellEditingStyleDelete" forKey:@"editingStyle"];
    
    self.chineseLabel = [UILabel new];
    
    self.chineseLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    self.chineseLabel.textColor = ColorWithRGB(0xffffff);
    self.chineseLabel.textAlignment = NSTextAlignmentLeft;
    
    [self.contentView addSubview:self.chineseLabel];
    
    [self.chineseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.contentView).offset(15 * SCREENH6);
    }];
    
    
    self.englishLabel = [UILabel new];
    
    self.englishLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.englishLabel.textColor = ColorWithRGB(0xffffff);
    self.englishLabel.textAlignment = NSTextAlignmentLeft;
    
    [self.contentView addSubview:self.englishLabel];
    
    [self.englishLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.chineseLabel);
        make.top.mas_equalTo(self.chineseLabel.mas_bottom).offset(2 * SCREENH6);
//        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
//        make.centerY.mas_equalTo(self.contentView);
    }];
    
    
    self.addLabel = [UILabel new];
    
    self.addLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.addLabel.textColor = ColorWithRGB(0xffffff);
    self.addLabel.backgroundColor = RED_COLOR;
    self.addLabel.textAlignment = NSTextAlignmentCenter;
    self.addLabel.hidden = NO;
    
    [self.contentView addSubview:self.addLabel];
    
    [self.addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(75 * SCREENH6);
        make.height.mas_equalTo(26 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
    }];
    
    
    self.reduceLabel = [UILabel new];
    
    self.reduceLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.reduceLabel.textColor = ColorWithRGB(0xffffff);
    self.reduceLabel.backgroundColor = RED_COLOR;
    self.reduceLabel.textAlignment = NSTextAlignmentCenter;
    self.addLabel.hidden = NO;
    
    [self.contentView addSubview:self.reduceLabel];
    
    [self.reduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.mas_equalTo(self.contentView);
        make.trailing.mas_equalTo(self.addLabel.mas_leading).offset(-5 * SCREENH6);
        make.top.width.height.mas_equalTo(self.addLabel);
    }];
    

    
    self.lineView = [UIView new];
    
    self.lineView.backgroundColor = [UIColor whiteColor];
    self.lineView.alpha = 0.1;
    
    [self.contentView addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
    
}


//- (void)showOrHiddenLabel{
//    
//    if (self.addLabel.hidden) {
//        
//        self.addLabel.hidden = NO;
//        self.reduceLabel.hidden = NO;
//        
//    }else{
//        
//        self.addLabel.hidden = YES;
//        self.reduceLabel.hidden = YES;
//        
//    }
//    
//    
//}


- (void)setModel:(OptionalModel *)model{
    
    _model = model;
    
    self.englishLabel.text = [NSString stringWithFormat:@"%@",model.symbol];
    self.chineseLabel.text = [NSString stringWithFormat:@"%@",model.ch_name];
//    self.addLabel.text
    NSDictionary * oopsDict = model.oops;
//
    self.addLabel.text = [NSString stringWithFormat:@"%@",oopsDict[@"ask"]];
    self.reduceLabel.text = [NSString stringWithFormat:@"%@",oopsDict[@"bid"]];
}


- (void)willTransitionToState:(UITableViewCellStateMask)state{
    
    [super willTransitionToState:state];
//
//    if (self.addLabel.hidden) {
//        
//        self.addLabel.hidden = NO;
//        self.reduceLabel.hidden = NO;
//
//    }else{
//        
//        self.addLabel.hidden = YES;
//        self.reduceLabel.hidden = YES;
//        
//    }
    
    if (state == UITableViewCellStateDefaultMask) {
        
        self.addLabel.hidden = NO;
        self.reduceLabel.hidden = NO;

    }else if (state == UITableViewCellStateShowingEditControlMask){
        
        self.addLabel.hidden = YES;
        self.reduceLabel.hidden = YES;
    }
    
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}





@end
